package selenium.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

public class ViewFilmPage extends AnyPage {

    @FindBy(tagName = "h2")
    private WebElement nameField;

    @FindBy(className = "loaned")
    private WebElement loanedField;

    @FindBy(className = "duration")
    private WebElement durationField;

    @FindBy(className = "rating")
    private WebElement ratingField;

    @FindBy(className = "notes")
    private WebElement notesField;

    @FindBy(xpath = "//div[@class='plotoutline']/div")
    private WebElement plotField;

    @FindBy(xpath = "//div[contains(@class,'maininfo')]//div[@class='languages']")
    private WebElement languagesField;

    @FindBy(xpath = "//img[@title='Remove']/../../a")
    private WebElement removeButton;

    public ViewFilmPage(PageManager pages) {
        super(pages);
    }

    public WebElement getNameField() {
        return nameField;
    }

    public WebElement getLoanedField() {
        return loanedField;
    }

    public WebElement getDurationField() {
        return durationField;
    }

    public WebElement getRatingField() {
        return ratingField;
    }

    public WebElement getLanguagesField() {
        return languagesField;
    }

    public WebElement getPlotField() {
        return plotField;
    }

    public WebElement getNotesField() {
        return notesField;
    }

    public ViewFilmPage ensurePageLoaded() {
        super.ensurePageLoaded();
        wait.until(presenceOfElementLocated(By.xpath("//img[@title='Remove']")));
        return this;
    }

    public void clickRemoveButton () {
        removeButton.click();
    }
}